import React from 'react'

import eventEmitter from '../components/event'

import '../css/Add.css'
class Add extends React.Component{
    constructor(props){
        super(props)
        this.state={

        }
    }
    render(h) {
        return (
            <div className='add-box'>
                <input type="text" className='inp' ref="input" />
                <input type="button" value="发布" onClick={()=>{
                    // console.log(this.refs.input.value)
                    let val=this.refs.input.value//拿到输入的内容
                    if(val.trim()==''){//为空判断
                        return alert('不能为空')
                    }
                    var message={//对象储存
                        content:val,
                        date:new Date().toLocaleString(),
                        status:0
                    }
                    //向公共组件发布一个自定义事件，携带上数据
                    eventEmitter.emit("sendMessageToNav",message)
                    this.refs.input.value=''
                }} />
            </div>
        )
    }
}

export default Add